@echo off
REM OpenHarmony Knowledge Service 启动脚本

echo =========================================
echo   OpenHarmony Knowledge Service
echo =========================================
echo.

REM 检查Java环境
java -version >nul 2>&1
if errorlevel 1 (
    echo 错误: 未找到Java运行环境
    echo 请安装Java 17或更高版本
    pause
    exit /b 1
)

echo Java环境正常
echo.

REM 设置环境变量
if not defined OH_CODE_PATH (
    set OH_CODE_PATH=..\ohcode
)

if not defined GLM_API_KEY (
    set GLM_API_KEY=df6af53dd93b4afe9c1f0781f198305a.zcW6GYuBCOz3Xb27
)

echo OHCode路径: %OH_CODE_PATH%
echo.

REM 检查ohcode目录
if not exist "%OH_CODE_PATH%" (
    echo 警告: ohcode目录不存在: %OH_CODE_PATH%
    echo 知识库服务将无法扫描代码
    echo.
)

REM 创建数据目录
if not exist "data\index" mkdir data\index
if not exist "logs" mkdir logs

REM 检查是否已编译
if not exist "target\openharmony-knowledge-service-1.0.0.jar" (
    echo 编译项目...
    call mvn clean package -DskipTests
    if errorlevel 1 (
        echo 编译失败
        pause
        exit /b 1
    )
)

REM 启动服务
echo 启动服务...
echo.

java -Xms512m -Xmx2048m ^
     -XX:+UseG1GC ^
     -Dfile.encoding=UTF-8 ^
     -jar target\openharmony-knowledge-service-1.0.0.jar ^
     --spring.profiles.active=prod

pause

